package com.nangle.managehost.manager;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.nangle.managehost.db.DBManager;
import com.nangle.managehost.db.SQLiteTemplate;
import com.nangle.managehost.entity.BedMessage;
import com.nangle.managehost.entity.DayThree;
import com.nangle.managehost.entity.Doctor;
import com.nangle.managehost.entity.MessageDay;
import com.nangle.managehost.entity.OperationMsg;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by YFB on 2017/4/13.
 */

public class NurseManager {
    private static NurseManager nurseManager = null;
    private static DBManager manager = null;
    private NurseManager(Context context) {
        manager = DBManager.getInstance(context,  "yjhcloud");
    }
    public static NurseManager getInstance(Context context) {

        if (nurseManager == null) {
            nurseManager = new NurseManager(context);
        }

        return nurseManager;
    }
    public long saveNurse(Doctor patient){
        SQLiteTemplate st = SQLiteTemplate.getInstance(manager, false);
        ContentValues contentValues = new ContentValues();

        contentValues.put("name",patient.getName());
        contentValues.put("title", patient.getTitle());
        contentValues.put("age", patient.getAge());

        return st.insert("nurse", contentValues);
    }
    public List<Doctor> getDoctorList(){
        SQLiteTemplate st = SQLiteTemplate.getInstance(manager, false);
        List<Doctor> list = st.queryForList(new SQLiteTemplate.RowMapper<Doctor>() {

            @Override
            public Doctor mapRow(Cursor cursor, int index) {
                Doctor notice = new Doctor();
                notice.setId(cursor.getString(cursor.getColumnIndex("_id")));
                notice.setName(cursor.getString(cursor
                        .getColumnIndex("name")));
                notice.setTitle(cursor.getString(cursor.getColumnIndex("title")));

                notice.setAge(cursor.getInt(cursor.getColumnIndex("age")));
                notice.setBedMessages(getbeds());
                notice.setDayThrees(getD());
                return notice;
            }

        }, "select * from nurse" , null);
        return list;
    }

    public Doctor getDoctor(String id){
        SQLiteTemplate st = SQLiteTemplate.getInstance(manager, false);
        return st.queryForObject(new SQLiteTemplate.RowMapper<Doctor>() {

            @Override
            public Doctor mapRow(Cursor cursor, int index) {
                Doctor notice = new Doctor();
                notice.setId(cursor.getString(cursor.getColumnIndex("_id")));
                notice.setName(cursor.getString(cursor
                        .getColumnIndex("name")));
                notice.setTitle(cursor.getString(cursor.getColumnIndex("title")));

                notice.setAge(cursor.getInt(cursor.getColumnIndex("age")));
                notice.setBedMessages(getbeds());
                notice.setDayThrees(getD());
                return notice;
            }

        }, "select * from nurse where _id=?", new String[] { id });
    }
    private List<BedMessage> getbeds(){
        SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = sDateFormat.format(new java.util.Date());

        List<OperationMsg> operationMsgs = new ArrayList<>();
        OperationMsg operationMsg = new OperationMsg();
        operationMsg.setTime(date+" 8:00");
        operationMsg.setOperationName("血压监测");

        OperationMsg operationMsg1 = new OperationMsg();
        operationMsg1.setTime(date+" 8:10");
        operationMsg1.setOperationName("血糖监测");

        OperationMsg operationMsg2 = new OperationMsg();
        operationMsg2.setTime(date+" 10:00");
        operationMsg2.setOperationName("胃镜检查");

        OperationMsg operationMsg3 = new OperationMsg();
        operationMsg3.setTime(date+" 14:00");
        operationMsg3.setOperationName("阑尾炎手术");

        operationMsgs.add(operationMsg);
        operationMsgs.add(operationMsg1);
        operationMsgs.add(operationMsg2);
        operationMsgs.add(operationMsg3);




        List<BedMessage> bedMessages = new ArrayList<>();
        BedMessage bedMessage1 = new BedMessage();
        bedMessage1.setBedNumber(3);
        bedMessage1.setPatientName("王小如");
        bedMessage1.setOperationMsgs(operationMsgs);

        BedMessage bedMessage2 = new BedMessage();
        bedMessage2.setBedNumber(4);
        bedMessage2.setPatientName("欧阳暮雪");
        bedMessage2.setOperationMsgs(operationMsgs);

        BedMessage bedMessage3 = new BedMessage();
        bedMessage3.setBedNumber(5);
        bedMessage3.setPatientName("牛晓倩");
        bedMessage3.setOperationMsgs(operationMsgs);

        BedMessage bedMessage4 = new BedMessage();
        bedMessage4.setBedNumber(8);
        bedMessage4.setPatientName("范丽宇");
        bedMessage4.setOperationMsgs(operationMsgs);

        bedMessages.add(bedMessage1);
        bedMessages.add(bedMessage2);
        bedMessages.add(bedMessage3);
        bedMessages.add(bedMessage4);
        return bedMessages;
    }
    private List<DayThree> getD(){
        List<DayThree> dayThrees = new ArrayList<>();

        DayThree dayThree1 = new DayThree();
        dayThree1.setDay("25日");
        List<MessageDay> messageDays = new ArrayList<>();
        messageDays.add(new MessageDay("8:00~12:00","门诊"));
        messageDays.add(new MessageDay("12:00~18:00","休班"));
        dayThree1.setMessageDays(messageDays);

        DayThree dayThree2 = new DayThree();
        dayThree2.setDay("26日");
        List<MessageDay> messageDays2 = new ArrayList<>();
        messageDays2.add(new MessageDay("8:00~12:00","专家门诊"));
        messageDays2.add(new MessageDay("12:00~18:00","技术研讨会"));
        dayThree2.setMessageDays(messageDays2);

        DayThree dayThree3 = new DayThree();
        dayThree3.setDay("27日");
        List<MessageDay> messageDays3 = new ArrayList<>();
        messageDays3.add(new MessageDay("8:00~18:00","休班"));
        messageDays3.add(new MessageDay("19:00~8:00","夜班"));
        dayThree3.setMessageDays(messageDays3);

        DayThree dayThree4 = new DayThree();
        dayThree4.setDay("28日");
        List<MessageDay> messageDays4 = new ArrayList<>();
        messageDays4.add(new MessageDay("8:00~12:00","休班"));
        messageDays4.add(new MessageDay("12:00~18:00","门诊"));
        dayThree4.setMessageDays(messageDays4);

        dayThrees.add(dayThree1);
        dayThrees.add(dayThree2);
        dayThrees.add(dayThree3);
        dayThrees.add(dayThree4);
        return dayThrees;
    }
}
